package com.hmall.common.domain;

import java.util.List;

public class CustomPageDTO<T> {
    protected Long total;    // 总记录数
    protected Long pages;    // 总页数
    protected List<T> list;  // 当前页的数据列表

    public CustomPageDTO() {
    }

    public CustomPageDTO(Long total, Long pages, List<T> list) {
        this.total = total;
        this.pages = pages;
        this.list = list;
    }

    // Getter 和 Setter 方法
    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Long getPages() {
        return pages;
    }

    public void setPages(Long pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    // 静态工厂方法，用于构建 CustomPageDTO 对象
    public static <T> CustomPageDTO<T> of(List<T> content, Long total, int pageSize) {
        long pages = (long) Math.ceil((double) total / pageSize); // 计算总页数
        return new CustomPageDTO<>(total, pages, content);
    }
}
